package com.bpmn.common.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;

/**
 * 公共返回前端
 *
 * @author Liuzheng
 * @date 2024年12月23日
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseResult<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 成功
     */
    public static final int SUCCESS = 200;

    /**
     * 失败
     */
    public static final int FAIL = 500;

    private int code;

    private String message;

    private T data;

    public static <T> ResponseResult<T> success() {
        return new ResponseResult<>(SUCCESS, "操作成功", null);
    }

    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<>(SUCCESS, "操作成功", data);
    }

    public static <T> ResponseResult<T> successStr(T data) {
        return new ResponseResult<>(SUCCESS, "操作成功", data);
    }

    public static <T> ResponseResult<T> success(String msg) {
        return new ResponseResult<>(SUCCESS, msg, null);
    }

    public static <T> ResponseResult<T> fail() {
        return new ResponseResult<>(FAIL, "操作失败", null);
    }

    public static <T> ResponseResult<T> fail(T data) {
        return new ResponseResult<>(FAIL, "操作失败", data);
    }

    public static <T> ResponseResult<T> fail(String msg) {
        return new ResponseResult<>(FAIL, msg, null);
    }

    public static <T> ResponseResult<T> fail(String msg, T data) {
        return new ResponseResult<>(FAIL, msg, data);
    }

    public static <T> ResponseResult<T> fail(int code, String msg) {
        return new ResponseResult<>(code, msg, null);
    }

}

